package com.zxs.admin.service.impl;

import client.CategoryClient;
import com.zxs.admin.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
import parm.PageParam;
import pojo.Category;
import utils.R;

/**
 * @author zxs
 * *9 18:28
 */
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryClient categoryClient;

    @Override
    public R getCategoryList(PageParam pageParam) {
        R r = categoryClient.categoryList(pageParam);
        return r;
    }

    /**
     * 添加类别
     * @param category
     * @return
     */
    @Override
    @CacheEvict(value = "list.category",allEntries = true)
    public R saveCategory(Category category) {
        R r = categoryClient.categorySave(category);
        return r;
    }

    /**
     * 删除某个类别
     * @param category
     * @return
     */
    @Override
    @Caching(
            evict = {
                    @CacheEvict(value="list.category",allEntries = true),
                    @CacheEvict(value = "category",allEntries = true)
            })
    public R removeCategory(Category category) {
        R r = categoryClient.categoryRemove(category);
        return r;
    }

    /**
     * 更新类别
     * @param category
     * @return
     */
    @Override
    @Caching(
            evict = {
        @CacheEvict(value="list.category",allEntries = true),
        @CacheEvict(value = "category",allEntries = true)
    })
    public R updateCategory(Category category) {
        R r = categoryClient.categoryUpdate(category);
        return r;
    }
}
